package com.lch.netty.bio.tomcat.http;

import java.io.IOException;
import java.io.OutputStream;

import lombok.Data;

/**
 * @author: liuchenhui
 * @create: 2019-10-14 11:44
 **/
@Data
public class Response {


    private final OutputStream outputStream;

    public Response(OutputStream outputStream) {
        this.outputStream = outputStream;
    }

    public void write(String content) throws IOException {
        //用的是HTTP协议，输出也要遵循HTTP协议
        //给到一个状态码 200
        StringBuilder sb = new StringBuilder();
        sb.append("HTTP/1.1 200 OK\n")
                .append("Content-Type: text/html;\n")
                .append("\r\n")
                .append(content);
        outputStream.write(sb.toString().getBytes());
        outputStream.close();
    }
}
